package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.community.domain.vo.HouseVos;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.House;
import com.ruoyi.community.service.IHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房屋Controller
 *
 * @author lj
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/community/house")
public class HouseController extends BaseController
{
    @Autowired
    private IHouseService houseService;

    /**
     * 查询房屋列表
     */
    @PreAuthorize("@ss.hasPermi('community:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(House house)
    {
        startPage();
        List<HouseVos> list = houseService.selectHouseLists(house);
        return getDataTable(list);
    }

    /**
     * 导出房屋列表
     */
    @PreAuthorize("@ss.hasPermi('community:house:export')")
    @Log(title = "房屋", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, House house)
    {
        List<House> list = houseService.selectHouseList(house);
        ExcelUtil<House> util = new ExcelUtil<House>(House.class);
        util.exportExcel(response, list, "房屋数据");
    }

    /**
     * 获取房屋详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseService.selectHouseById(id));
    }

    /**
     * 新增房屋
     */
    @PreAuthorize("@ss.hasPermi('community:house:add')")
    @Log(title = "房屋", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody House house)
    {
        return toAjax(houseService.insertHouse(house));
    }

    /**
     * 修改房屋
     */
    @PreAuthorize("@ss.hasPermi('community:house:edit')")
    @Log(title = "房屋", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody House house)
    {
        return toAjax(houseService.updateHouse(house));
    }

    /**
     * 删除房屋
     */
    @PreAuthorize("@ss.hasPermi('community:house:remove')")
    @Log(title = "房屋", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseService.updateHouseByIds(ids));
    }
}
